package bancosys.tec.persist.audit;

import bancosys.tec.persist.authorization.Authorizable;
import bancosys.tec.persist.authorization.AuthorizationManager;

/**
 * @created 08/11/2007
 * @author Gustavo Almeida
 */
public class DefaultAuditLogManager implements AuditLogManager {
    private AuthorizationManager authorizationManager;

    /**
     * Devolve <code>true</code> caso a entidade deva ser auditada, <code>false</code> caso contrário.
     * 
     * @param entity entidade.
     * @return <code>true</code> caso a entidade deva ser auditada, <code>false</code> caso contrário.
     */
    public boolean isAuditable(Auditable entity) {
        if (!(entity instanceof Authorizable)) {
            return false;
        }

        Authorizable authorizable = (Authorizable) entity;
        if (authorizable.getAuth()) {
            return false;
        }

        return this.authorizationManager.isAuthorizable(authorizable);
    }

    /**
     * Define o authorizationManager.
     * 
     * @param authorizationManager O authorizationManager a ser definido.
     */
    public void setAuthorizationManager(AuthorizationManager authorizationManager) {
        this.authorizationManager = authorizationManager;
    }
}
